package com.xiaoyao.myframeapp.location;


import com.xiaoyao.myframeapp.FrameApplication;
import com.xiaoyao.myframeapp.core.BaseEntity;
import com.xiaoyao.myframeapp.core.transformer.RxSchedulers;
import com.xiaoyao.myframeapp.core.subscriber.BaseObserver;
import com.xiaoyao.myframeapp.mvp.base.BaseModel;
import com.xiaoyao.myframeapp.utils.L;

/**
 * @author xiaoyao
 * @mail xiao80206040@qq.com
 * @explain
 * @Created by Administrator on 2017/2/27 0027.
 */
public class UploadLatLonModel extends BaseModel {


    public void uploadLatLon(
//            BaseActivity activity,
            String longitude,
            String latitude,
            String userId,
            final InfoHint infoHint) {

        if (infoHint == null)
            throw new RuntimeException("InfoHint不能为空");

        httpService.uploadLatLon(
                longitude,
                latitude,
                userId,
//                JPushInterface.getRegistrationID(WoxingApplication.getmContext()), /*TODO 消息推送设备标识*/
                "2"/*TODO 手机型号。1：iOS，2：Android*/
        )
//                .compose(activity.<BaseEntity<Boolean>>bindToLifecycle())
                .compose(RxSchedulers.<BaseEntity<Boolean>>compose())//完成返回Activity 空指针
                .subscribe(new BaseObserver<Boolean>(FrameApplication.getmContext()) {
                    @Override
                    protected void onHandleSuccess(Boolean isData) {
                        L.e("TestPresenter", "onHandleSuccess");
                        infoHint.success(isData);
                        L.e("TestPresenter", "onHandleSuccess");
                    }

                    @Override
                    protected void onHandleError(String msg) {
                        super.onHandleError(msg);
                        infoHint.fail(msg);
                        L.e("TestPresenter" + "onHandleError");
                    }
                });


    }


    //通过接口产生信息回调
    public interface InfoHint {
        void success(Boolean isData);

        void fail(String str);

    }
}
